1
|
|
|
var program = require('commander'); |
2
|
|
|
var shell = require('shelljs'); |
3
|
|
|
var chalk = require('chalk'); |
4
|
|
|
var emoji = require('node-emoji'); |
5
|
|
|
var co = require('co'); |
6
|
|
|
var prompt = require('co-prompt'); |
7
|
|
|
|
8
|
|
|
var enviroment = process.env.npm_package_config_enviroment; |
9
|
|
|
|
10
|
|
|
shell.mkdir('-p',['applications/assets/icons']); |
11
|
|
|
|
12
|
|
|
process.stdout.write(chalk.gray(emoji.emojify('[ ] Build Server Vagrant (' + enviroment + ")\n"))); |
13
|
|
|
|
14
|
|
|
if ( enviroment === 'dev' ){ |
15
|
|
|
|
16
|
|
|
vagrantId = shell.exec("vagrant global-status | grep d1b0server | awk '{ print $1}'", {silent:true}); |
|
|
|
|
17
|
|
|
|
18
|
|
|
var vagrantCode; |
19
|
|
|
if ( vagrantId.code !== 0 ){ |
20
|
|
|
process.stderr.write(chalk.bgRed.white(emoji.emojify("[:heavy_multiplication_x: ] Errore: "+vagrantId.stderr+ " - "+vagrantId.output))); |
21
|
|
|
process.exit(1); |
|
|
|
|
22
|
|
|
} else { |
23
|
|
|
vagrantCode = vagrantId.output.trim(); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
if ( !vagrantCode ) { |
27
|
|
|
process.stdout.write(chalk.yellow(emoji.emojify("[:raised_hand: ] Vagrant server not found \n"))); |
28
|
|
|
|
29
|
|
|
shell.exec('./scripts/generatekey.sh'); |
30
|
|
|
shell.exec('./scripts/generateSSL.sh'); |
31
|
|
|
shell.exec('./scripts/roles_update.sh'); |
32
|
|
|
|
33
|
|
|
shell.cd('server/'); |
34
|
|
|
|
35
|
|
|
upVagrant = shell.exec("vagrant up", {silent:true}); |
|
|
|
|
36
|
|
|
if ( upVagrant.code !== 0 ){ |
37
|
|
|
process.stderr.write(chalk.bgRed.white(emoji.emojify("[:heavy_multiplication_x: ] Errore: "+upVagrant.stderr+ " - "+upVagrant.output))); |
38
|
|
|
process.exit(1); |
|
|
|
|
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
process.stdout.write("Vagrant server UP.\n"); |
42
|
|
|
|
43
|
|
|
|
44
|
|
|
shell.echo('Install Server Required Package and Config'); |
45
|
|
|
ansibleProc = shell.exec('ansible-playbook -i '+enviroment+'.hosts site.yml', {silent:true}); |
|
|
|
|
46
|
|
|
if ( ansibleProc.code !== 0 ){ |
47
|
|
|
process.stderr.write(chalk.bgRed.white(emoji.emojify("[:heavy_multiplication_x: ] Errore ansible site.yml"))); |
48
|
|
|
process.stderr.write(chalk.gray(ansibleProc.stdout+"\n")); |
49
|
|
|
process.stderr.write(chalk.red(ansibleProc.stderr+"\n")); |
50
|
|
|
|
51
|
|
|
process.exit(1); |
|
|
|
|
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
process.stdout.write(chalk.bgGreen.black(emoji.emojify('[:heavy_check_mark: ] Vagrant server installation packages completed.' + "\n"))); |
55
|
|
|
|
56
|
|
|
shell.cd('..'); |
57
|
|
|
|
58
|
|
|
} else { |
59
|
|
|
process.stdout.write(chalk.gray(emoji.emojify("[:world_map: ] Find vagrant server: "+vagrantCode+". Skip creation.\n" ))); |
60
|
|
|
// non funziona vagrant up by name or uuid |
61
|
|
|
// var upVagrant = shell.exec("vagrant up "+vagrantCode); |
62
|
|
|
|
63
|
|
|
shell.cd('server/'); |
64
|
|
|
|
65
|
|
|
upVagrant = shell.exec("vagrant up", {silent:true}); |
66
|
|
|
if ( upVagrant.code !== 0 ){ |
67
|
|
|
process.stderr.write(chalk.bgRed.white(emoji.emojify("[:heavy_multiplication_x: ] Errore ansible site.yml"))); |
68
|
|
|
process.stderr.write(chalk.gray(ansibleProc.stdout+"\n")); |
|
|
|
|
69
|
|
|
process.stderr.write(chalk.red(ansibleProc.stderr+"\n")); |
70
|
|
|
process.exit(1); |
|
|
|
|
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
process.stdout.write(chalk.bgGreen.black(emoji.emojify('[:heavy_check_mark: ] Vagrant server UP!' + "\n"))); |
74
|
|
|
|
75
|
|
|
shell.cd('..'); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
} else { |
79
|
|
|
|
80
|
|
|
shell.echo('Install Server Required Package and Config'); |
81
|
|
|
ansibleProc = shell.exec('ansible-playbook -i '+enviroment+'.hosts site.yml', {silent:true}); |
82
|
|
|
if ( ansibleProc.code !== 0 ){ |
83
|
|
|
process.stderr.write(chalk.bgRed.white(emoji.emojify("[:heavy_multiplication_x: ] Errore: "+ansibleProc.stderr+ " - "+ansibleProc.output))); |
84
|
|
|
process.exit(1); |
|
|
|
|
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
} |
88
|
|
|
|